 package com.tnt.hpit.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.tnt.hpit.gamelogic.GameControl;
import com.tnt.hpit.helper.ControllerInputMultiplexer;
import com.tnt.hpit.helper.OrthoCamController;
import com.tnt.hpit.shared.Constants;

public abstract class AbstractScreen implements Screen{
	protected SpriteBatch sb;
	protected SpriteBatch sb_nocamera;
	protected GameControl gameControl;
	protected OrthographicCamera camera;
	private OrthoCamController orthoCamController;
	protected ControllerInputMultiplexer controllerIM;
	private BitmapFont frameNum;
	
	
	public AbstractScreen ( GameControl gameControl ){
		this.gameControl = gameControl;
		sb = new SpriteBatch();
		sb_nocamera = new SpriteBatch();
		camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
		frameNum = new BitmapFont();
		camera.position.set(Constants.SCREEN_WIDTH / 2, Constants.SCREEN_HEIGHT / 2, 0);
		orthoCamController = new OrthoCamController(camera);
		controllerIM = new ControllerInputMultiplexer();
	}
	
	@Override
	public void show() {
		controllerIM.getIM().addProcessor(orthoCamController);
	}
	@Override
	public void resume() {
	}

	@Override
	public void pause() {
	}
	
	@Override
	public void resize(int arg0, int arg1) {
	}
	
	@Override
	public void render(float arg0) {
		Gdx.gl.glClearColor( 0f, 0f, 0f, 1f );
		Gdx.gl.glClear( GL20.GL_COLOR_BUFFER_BIT );
		camera.update();
		sb.begin();
		sb.setProjectionMatrix(camera.combined);
		sb.end();
	}

	@Override
	public void hide() {
	}

	@Override
	public void dispose() {
	}
	protected void showFrameNumber(){
		sb_nocamera.begin();
		frameNum.draw(sb_nocamera, String.valueOf(Gdx.graphics.getFramesPerSecond()), 0, Constants.SCREEN_HEIGHT);
		sb_nocamera.end();
	}
}
